package net.halflite.mzkr.action.regist;

import javax.annotation.Resource;

import net.halflite.mzkr.service.RegistedUserService;
import net.halflite.mzkr.type.TempUserType;

import org.apache.struts.action.ActionMessages;
import org.seasar.struts.annotation.Execute;
import org.seasar.struts.annotation.Mask;
import org.seasar.struts.annotation.Msg;

/** ユーザー本登録のアクションクラス */
public class MailAction {

	@Resource
	private RegistedUserService registedUserService;
	
	@Mask(mask = "[0-9a-f]{32}", msg = @Msg(key = "errors.invalid.hash"))
	public String hash;
	
	/** メールに記載された本登録URL */
	@Execute(urlPattern = "{hash}", validate = "validate", input = "fault.jsp")
    public String index() {
		registedUserService.registMail(hash);
        return "complete?redirect=true";
    }

	/** 完了画面 */
	@Execute(validator = false)
    public String complete() {
        return "complete.jsp";
    }

	public ActionMessages validate() {
		return registedUserService.validateHash(hash, TempUserType.MAIL);
	}
}
